//
//  TTAnnotationServer.swift
//  TTCOM
//
//  Created by Toj on 3/8/21.
//

import Foundation

open class TTAnnotationServer: NSObject {
    
    private override init() { }
    public static let shared = TTAnnotationServer()
    public var didJoined: TTPanoDidJoined? {
        didSet {
            service?.didJoined = didJoined
        }
    }
    
    private var annotation: TTAnnotationModel?
    
    private var service: PanoAnnotationService?

    public func setupServer(annotation: TTAnnotationModel) {
        
        self.annotation = annotation
        let appId = annotation.appId
        let rtcServer = annotation.rtcServer
        let token = annotation.token
        let channelId = annotation.channelId
        let userid = annotation.userid
        
        service = PanoAnnotationService.shared
        service?.setupServerParameter(appID: appId, rtcServer: rtcServer)
        service?.setupChannelParameter(token: token, channelId: channelId, userid: userid)
    }
    
    public func joinChannel() {
        service?.joinChannel()
    }
    
    public func startAnnotation(view: TTView) {
        let annotationId = annotation?.annotationId ?? ""
        service?.joinExternalAnnotation(annotationId: annotationId)
        service?.startAnnotation(view: view)
    }
    
    public func stopAnnotation() {
        service?.stopAnnotation()
        service = nil
    }
    
    public func setRoleType(role: Int) {
        service?.setRoleType(role: role)
    }
} 
